﻿using SilverCrmSoap.CrmSdk;



namespace SLTimeZoneHelper.CRM2011
{
	internal static class EntityExtensions
	{
		internal static T GetValue<T>(this Entity entity, string name)
		{
			T result = default(T);

			if (entity.Attributes.ContainsKey(name)) 
				result = entity.GetAttributeValue<T>(name);
				//result = entity.Attributes.ItemByKey<T>(name);

			return result;
		}

		internal static T GetAliasedValue<T>(this Entity entity, string name)
		{
			T result = default(T);
			if (entity.Attributes.ContainsKey(name))
			{
				AliasedValue aliasedValue = entity.GetValue<AliasedValue>(name);
				result = (T)aliasedValue.Value;
			}

			return result;
		}
	}
}